#include "graph_support/alg_correctness_tests/generate_graph/OperationsBsdGenerator.h"

#include "graph_support/impls/vector/VectorGraph.h"


using namespace generate_graph;

typedef GRAPH_SUPPORT_NS::impls::vector::VectorGraphTmpl<
		int,
		generate_graph::FlowEdgeAttributes4UnitTests,
		stdext::hash< int >,
		stdext::equal_to< int >
		> DefaultGenerationGraph;
// TODO: graph name

OperationsBsdGenerator::OperationsBsdGenerator(
		const std::string & name,
		size_t initVerticesCount,
		const std::vector< IGraphOperationPtr > & operations,
		NewGraphFn newGraphFn,
		bool generateBidirected
)
	: name( name )
	, initVerticesCount( initVerticesCount )
	, generateBidirected( generateBidirected )
	, operations( operations )
	, newGraphFn( newGraphFn )
{
	if ( this->newGraphFn == NULL )
	{
		this->newGraphFn = & NewGraphFnTmpl< DefaultGenerationGraph >;
	}
}

IGraphGenerator::GraphPtr OperationsBsdGenerator::generate()
{
	typedef DefaultGenerationGraph::GrVertex GrVertex;

	std::vector< GrVertex > vertices( initVerticesCount );
	for ( int i = 0; i < initVerticesCount; i++ )
	{
		vertices[i] = i;
	}

	GraphPtr gr = newGraphFn( vertices, generateBidirected );
	std::for_each( operations.begin(), operations.end(),
			boost::bind( & IGraphOperation::applyOperation, _1, boost::ref( gr ) ) );

	return gr;
}

std::string OperationsBsdGenerator::getName()
{
	return name;
}
